﻿using MediatR;
using S.Produce.Domains;
using S.Produce.Infrastructure;
using S.Produce.Read.Api.Application.Commands.HistoryCommands;

namespace S.Produce.Read.Api.Application.CommandHandlers.HistoryCommandHandlers
{
    public class HistoryGetInfoCommandHandler : IRequestHandler<HistoryGetInfoCommand, History>
    {
        private readonly IRepository<History> _repository;

        public HistoryGetInfoCommandHandler(IRepository<History> repository)
        {
            _repository = repository;
        }

        public async Task<History> Handle(HistoryGetInfoCommand request, CancellationToken cancellationToken)
        {
            var info = await _repository.SelAllAsync(x => x.Earbugles == request.Earbugles && x.AtPresentParity == request.AtPresentParity);
            return info.FirstOrDefault();
        }
    }
}
